import { defineStore } from 'pinia';
import { Session } from '/@/utils/storage';

/**
 * 用户信息
 * @methods setUserInfos 设置用户信息
 */
export const useUserInfo = defineStore('userInfo', {
	state: (): UserInfosState => ({
		userInfos: {
			avatarPath: '',
			nickName: '',
			roles: [],
			authBtnList: [],
			photo: '',
			id: '',
			time: 0,
			deptId: '',
			userName: ''
		},
	}),
	actions: {
		async setUserInfos(authBtns = null) {
			// 存储用户信息到浏览器缓存
			if (Session.get('userInfo')) {
				this.userInfos = Session.get('userInfo');
			}
			if (authBtns) {
				this.userInfos.authBtnList = authBtns
			}
		},
	},
});
